package day6.homework;

import java.util.*;

public class Ball {
    //机器生成的红号
    static Set<Integer> set = new TreeSet<>();//可以对String、数字类型排序
    //机器生成的蓝号
    static Integer blue;
    //用户的红号
    static Set<Integer> userSet = new TreeSet<>();
    //用户的蓝号
    static Integer userBlue;
    //中奖红号的数量
    static int redCount;
    //中奖蓝号的数量
    static int blueCount;

    public static void main(String[] args) throws InterruptedException {
//        Set sets = new HashSet();
//        sets.add(null);
//        Map map = new HashMap();
//        //16 0.75 8 6 64...
//        map.put(null,null);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的6个红号(1-33)");
        while (userSet.size()<6){
            int n = sc.nextInt();
            if (n<1||n>33) continue;
            userSet.add(n);
        }
        System.out.println("请输入蓝号:(1-16)");
        while (true){
            int n = sc.nextInt();
            if (n<1||n>16) continue;
            userBlue = n;
            break;
        }
        System.out.println("您投注的红号:"+userSet+",蓝号:"+userBlue);
        System.out.println("系统开始生成双色球号码,请等待...3秒");
        for (int i = 0;i<3;i++){
            Thread.sleep(1000);
            System.out.println("请稍等.."+(3-i)+"s");
        }
        //给红球随机赋值
        Random r = new Random();
        while (set.size()<6){
            set.add(r.nextInt(33)+1);
        }
        blue = r.nextInt(16)+1;
        System.out.println("双色球号码生成成功！");
        System.out.println("红号:"+set+",蓝号:"+blue);
        //结果1：统计 红球和蓝球 相同的个数
        stats();
        //结果2：计算金额
        result();
    }
    public static void stats() throws InterruptedException {
        //交集
        System.out.println("统计结果...");
        Thread.sleep(1000);
        Set<Integer> newUser = new TreeSet<>(userSet);
        newUser.retainAll(set);//统计相同的部分
        redCount = newUser.size();
        if (blue == userBlue) blueCount++;
        System.out.println("您中了"+redCount+"个红号,"+blueCount+"个蓝号");
    }
    public static void result(){
        if (0<redCount&&redCount<3&&blueCount==1)
            System.out.println("恭喜您获得六等奖！奖品为5元");
        else if (redCount==4&&blueCount==0)
            System.out.println("恭喜您获得五等奖！奖品为10元");
        else if (redCount==3&&blueCount==1)
            System.out.println("恭喜您获得五等奖！奖品为10元");
        else if (redCount==5&&blueCount==0)
            System.out.println("恭喜您获得四等奖！奖品为200元");
        else if (redCount==4&&blueCount==1)
            System.out.println("恭喜您获得四等奖！奖品为200元");
        else if (redCount==5&&blueCount==1)
            System.out.println("恭喜您获得三等奖！奖品为3000元");
        else if (redCount==6&&blueCount==0)
            System.out.println("恭喜您获得二等奖！奖品为150000元");
        else if (redCount==6&&blueCount==1)
            System.out.println("恭喜您获得一等奖！奖品为500000元");
        else System.out.println("很遗憾 您未获得任何奖项！");
    }
}
